<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="行业类别id" prop="industryCategory">
      <el-input v-model="dataForm.industryCategory" placeholder="行业类别id"></el-input>
    </el-form-item>
    <el-form-item label="附带资产id" prop="attachedAssets">
      <el-input v-model="dataForm.attachedAssets" placeholder="附带资产id"></el-input>
    </el-form-item>
    <el-form-item label="出售价格" prop="salePrice">
      <el-input v-model="dataForm.salePrice" placeholder="出售价格"></el-input>
    </el-form-item>
    <el-form-item label="省份" prop="province">
      <el-input v-model="dataForm.province" placeholder="省份"></el-input>
    </el-form-item>
    <el-form-item label="城市" prop="city">
      <el-input v-model="dataForm.city" placeholder="城市"></el-input>
    </el-form-item>
    <el-form-item label="企业类型id" prop="enterpriseTypeId">
      <el-input v-model="dataForm.enterpriseTypeId" placeholder="企业类型id"></el-input>
    </el-form-item>
    <el-form-item label="纳税类型id" prop="taxTypeId">
      <el-input v-model="dataForm.taxTypeId" placeholder="纳税类型id"></el-input>
    </el-form-item>
    <el-form-item label="注册资本" prop="registeredCapital">
      <el-input v-model="dataForm.registeredCapital" placeholder="注册资本"></el-input>
    </el-form-item>
    <el-form-item label="开业日期" prop="openingDate">
      <el-input v-model="dataForm.openingDate" placeholder="开业日期"></el-input>
    </el-form-item>
    <el-form-item label="是否开户0-已开基本户1-未开基本户" prop="hasAccount">
      <el-input v-model="dataForm.hasAccount" placeholder="是否开户0-已开基本户1-未开基本户"></el-input>
    </el-form-item>
    <el-form-item label="是否优选0-特价1-优选" prop="featured">
      <el-input v-model="dataForm.featured" placeholder="是否优选0-特价1-优选"></el-input>
    </el-form-item>
    <el-form-item label="公司名称" prop="name">
      <el-input v-model="dataForm.name" placeholder="公司名称"></el-input>
    </el-form-item>
    <el-form-item label="有形资产" prop="tangibleAssets">
      <el-input v-model="dataForm.tangibleAssets" placeholder="有形资产"></el-input>
    </el-form-item>
    <el-form-item label="无形资产" prop="intangibleAssets">
      <el-input v-model="dataForm.intangibleAssets" placeholder="无形资产"></el-input>
    </el-form-item>
    <el-form-item label="经营范围" prop="businessScope">
      <el-input v-model="dataForm.businessScope" placeholder="经营范围"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          industryCategory: '',
          attachedAssets: '',
          salePrice: '',
          province: '',
          city: '',
          enterpriseTypeId: '',
          taxTypeId: '',
          registeredCapital: '',
          openingDate: '',
          hasAccount: '',
          featured: '',
          name: '',
          tangibleAssets: '',
          intangibleAssets: '',
          businessScope: ''
        },
        dataRule: {
          industryCategory: [
            { required: true, message: '行业类别id不能为空', trigger: 'blur' }
          ],
          attachedAssets: [
            { required: true, message: '附带资产id不能为空', trigger: 'blur' }
          ],
          salePrice: [
            { required: true, message: '出售价格不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省份不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '城市不能为空', trigger: 'blur' }
          ],
          enterpriseTypeId: [
            { required: true, message: '企业类型id不能为空', trigger: 'blur' }
          ],
          taxTypeId: [
            { required: true, message: '纳税类型id不能为空', trigger: 'blur' }
          ],
          registeredCapital: [
            { required: true, message: '注册资本不能为空', trigger: 'blur' }
          ],
          openingDate: [
            { required: true, message: '开业日期不能为空', trigger: 'blur' }
          ],
          hasAccount: [
            { required: true, message: '是否开户0-已开基本户1-未开基本户不能为空', trigger: 'blur' }
          ],
          featured: [
            { required: true, message: '是否优选0-特价1-优选不能为空', trigger: 'blur' }
          ],
          name: [
            { required: true, message: '公司名称不能为空', trigger: 'blur' }
          ],
          tangibleAssets: [
            { required: true, message: '有形资产不能为空', trigger: 'blur' }
          ],
          intangibleAssets: [
            { required: true, message: '无形资产不能为空', trigger: 'blur' }
          ],
          businessScope: [
            { required: true, message: '经营范围不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/core/companytransfer/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.industryCategory = data.companyTransfer.industryCategory
                this.dataForm.attachedAssets = data.companyTransfer.attachedAssets
                this.dataForm.salePrice = data.companyTransfer.salePrice
                this.dataForm.province = data.companyTransfer.province
                this.dataForm.city = data.companyTransfer.city
                this.dataForm.enterpriseTypeId = data.companyTransfer.enterpriseTypeId
                this.dataForm.taxTypeId = data.companyTransfer.taxTypeId
                this.dataForm.registeredCapital = data.companyTransfer.registeredCapital
                this.dataForm.openingDate = data.companyTransfer.openingDate
                this.dataForm.hasAccount = data.companyTransfer.hasAccount
                this.dataForm.featured = data.companyTransfer.featured
                this.dataForm.name = data.companyTransfer.name
                this.dataForm.tangibleAssets = data.companyTransfer.tangibleAssets
                this.dataForm.intangibleAssets = data.companyTransfer.intangibleAssets
                this.dataForm.businessScope = data.companyTransfer.businessScope
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/core/companytransfer/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'industryCategory': this.dataForm.industryCategory,
                'attachedAssets': this.dataForm.attachedAssets,
                'salePrice': this.dataForm.salePrice,
                'province': this.dataForm.province,
                'city': this.dataForm.city,
                'enterpriseTypeId': this.dataForm.enterpriseTypeId,
                'taxTypeId': this.dataForm.taxTypeId,
                'registeredCapital': this.dataForm.registeredCapital,
                'openingDate': this.dataForm.openingDate,
                'hasAccount': this.dataForm.hasAccount,
                'featured': this.dataForm.featured,
                'name': this.dataForm.name,
                'tangibleAssets': this.dataForm.tangibleAssets,
                'intangibleAssets': this.dataForm.intangibleAssets,
                'businessScope': this.dataForm.businessScope
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
